#define _USE_MATH_DEFINES

#include "matrixCal.h"

#include <iostream>
#include <fstream>
#include <vector>
#include <cmath>
#include <Eigen/Dense>

using namespace std;
using namespace Eigen;

#define DIM 64

#define NODE_NUM_AC 18
#define BRANCH_NUM_AC 36
#define NODE_NUM_DC 4
#define BRANCH_NUM_DC 9

#define PI acos(-1.0)

class Capacitor
{
public:
	double cap_g;
	double cap_v;
	double cap_ib;
	double cap_jh;
};

//Inductor
class Inductor
{
public:
	double ind_g;
	double ind_v;
	double ind_ib;
	double ind_jh;
};

class Switch
{
public:
	double g;
	double gon;
	double goff;
};

class VSC
{
public:
	double g_vsc;
	double gon_vsc;
	double goff_vsc;
	double g_snubber;

};

//PV arrays
static double dV[4 * DIM], V_PV_V_his[4 * DIM];
static double parPV[4 * DIM][2];
static double dk[4 * DIM];
static double V_PV_V[4 * DIM], I_PV_A[4 * DIM];
static double V_PV_kV[4 * DIM], I_PV_kA[4 * DIM];
static double Npar[4 * DIM], Nser[4 * DIM];
static double Isc1_PV[4 * DIM], par_PV_b1[4 * DIM], par_PV_c1[4 * DIM], Voc1_PV[4 * DIM];
static int Count_k[4 * DIM];

//Boost
static int STATUS_his[4 * DIM][2];

//LC Filter
static double G_filt_R1[4 * DIM], G_filt_R2[4 * DIM];

//Transformer
static Matrix<double, 2, 2> G_trans_PVunit[4 * DIM];
static Matrix<double, 2, 2> parB_trans_PVunit[4 * DIM];
static Matrix<double, 2, 1> J_trans_A_PVunit[4 * DIM], J_trans_B_PVunit[4 * DIM], J_trans_C_PVunit[4 * DIM];

//Y Calculation (DCside)
static Matrix <double, NODE_NUM_DC, BRANCH_NUM_DC> A2;
static Matrix <double, BRANCH_NUM_DC, NODE_NUM_DC> A2_transpose;
static Matrix <double, BRANCH_NUM_DC, BRANCH_NUM_DC> Yg2[4 * DIM];
static Matrix <double, NODE_NUM_DC, 1> V_DC[4 * DIM];

//Y Calculation (ACside)
static Matrix <double, NODE_NUM_AC, BRANCH_NUM_AC> A1;
static Matrix <double, BRANCH_NUM_AC, NODE_NUM_AC> A1_transpose;
static Matrix <double, BRANCH_NUM_AC, BRANCH_NUM_AC> Yg1[4 * DIM];

static Matrix <double, NODE_NUM_AC - 3, 3> Y21[4 * DIM];
static Matrix <double, NODE_NUM_AC - 3, NODE_NUM_AC - 3> Y22_inv[4 * DIM];
static Matrix <double, NODE_NUM_AC - 3, 1> Jin[4 * DIM];

int pvmodel_pre_dc(double* _DELT, double* _PVarray_pars, double* _Boost_pars, double* _CPB_pars, double* _VSC_pars, double* _DATA_OUT, int* Dim);
int pvmodel_dc(int* _SW, double* _Vchar, double* _idc_source, double* _DATA_OUT, int* Dim);
int pvmodel_pre_ac(double* _G_PVunit, double* _INJ_ABC, double* _DELT, double* _VSC_pars, double* _LC_pars, double* _PVunit_Bre_pars, double* _Trans_pars, double* _DATA_OUT, int* Dim);
int pvmodel_ac(double* _G_PVunit, double* _INJ_ABC, double* _V_ABC, int* _Dblk1, int* _SW, double* _VdcBus, double* _DATA_OUT, int* Dim);
